package de.tu_darmstadt.gdi.battleship.gui;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.util.Locale;

import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;

import translator.TranslatableGUIElement;
import translator.Translator;
/**
 * @author Janos Klieber
 */
public class OptionMenu extends JFrame
{
	private JComboBox cbSkin = new JComboBox();
	private JComboBox cbMode = new JComboBox();
	private JComboBox cbDiff = new JComboBox();
	private String[] setup = new String[3];
	private String[] skins = {"defaultskin", "penis"};
	private String[] mode = {"normal","limited shots"};
	private String[] diffs = {"easy", "normal"};
	private BattleWindow bw;
	
	public OptionMenu(BattleWindow bw, String text, Locale locTarg) {
		super(text);
		setSize(350,300);
		setLocation(450,250);
		setLayout(new GridLayout(4,2,30,40));
		this.bw = bw;
		
		Translator trans = new Translator("msg", locTarg);
		TranslatableGUIElement transEle = trans.getGenerator();
		
		
		add(transEle.generateJLabel("selskin"));
		
		for(String s : skins)
			cbSkin.addItem(s);
		
		add(cbSkin);
		
		add(transEle.generateJLabel("selmode"));
		
		for(String s : mode)
			cbMode.addItem(s);
		
		add(cbMode);
		
		add(transEle.generateJLabel("seldiff"));
		
		for(String s : diffs)
			cbDiff.addItem(s);
		
		add(cbDiff);
		
		AbstractButton apl = transEle.generateJButton("apl");
		apl.addActionListener(new AbstractAction(){
			public void actionPerformed( ActionEvent e ) {
				applySettings();
				setVisible(false);
		      }
		});
		AbstractButton abo = transEle.generateJButton("abo");
		abo.addActionListener(new AbstractAction(){
			{ putValue( Action.NAME, "Abort" );
			}
			public void actionPerformed( ActionEvent e ) {
				setVisible(false);
		      }
		});
		
		transEle.translateGUIElements();

		add(apl);
		add(abo);
			}

	public void applySettings()
	{
		bw.getBattlePanel().changeSkin(skins[cbSkin.getSelectedIndex()]);
		
		setup[0] = mode[cbMode.getSelectedIndex()];
		setup[1] = diffs[cbDiff.getSelectedIndex()];
		
	}
}
